package com.qf.shopping.controll.activityControll;

import com.qf.shopping.pojo.activity.ActivityCategory;
import com.qf.shopping.service.activityService.IAcitvityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: Mawentao
 * @Date: 2019/5/9 0009 11:21
 * @Description:
 */
@Controller
@RequestMapping("/activitycategory")
public class ActivityCategoryControll {

    @Autowired
    private IAcitvityService acitvityService = null;

    /**
     * 加载列表
     * @param model
     * @return
     */
    @GetMapping("/activitycategory")
    public String getList(Model model){
        List<ActivityCategory> activityCategorys = acitvityService.findActivityCategory(null,0);
        model.addAttribute("activityCategory",activityCategorys);
        return "/activity/activityCategory/list";
    }

    /**
     * 搜索功能
     * @return
     */
    @PostMapping("/getactivitycategory")
    public String getActivityCategory(Model model,String name){
        List<ActivityCategory> activityCategorys = acitvityService.findActivityCategoryLike(name);
        model.addAttribute("activityCategory",activityCategorys);
        return "/activity/activityCategory/list";
    }

    /**
     * 新增活动类型
     * @return
     */
    @PostMapping("/addactivitycategory")
    public String addActivity(ActivityCategory activityCategory){
        acitvityService.insertActivityCategory(activityCategory);
        return "redirect:/activitycategory/activitycategory";
    }

    /**
     * 删除活动类型
     * @param id
     * @return
     */
    @GetMapping("/deleteactivitycategory/{id}")
    public String updateActivityCategory(@PathVariable("id")Long id){
        acitvityService.deleteActivityCategory(id);
        return "redirect:/activitycategory/activitycategory";
    }

    /**
     * 跳转到更新页面
     * @param model
     * @param id
     * @return
     */
    @GetMapping("/updateactivitycategory/{id}")
    public String updateActivityCategory(Model model,@PathVariable("id")Long id){
        ActivityCategory activityCategory = acitvityService.getActivityCategory(id);
        model.addAttribute("activityCategory",activityCategory);
        return "/activity/activityCategory/update";
    }

    /**
     * 编辑活动类型
     * @param activityCategory
     * @return
     */
    @PostMapping("updateactivitycategory")
    public String updateActivityCategory(ActivityCategory activityCategory){
        acitvityService.updateActivityCategory(activityCategory);
        return "redirect:/activitycategory/activitycategory";
    }
}
